package com.flying.pas.config.service;

import java.util.Date;

import com.flying.common.annotation.DaoCreate;
import com.flying.common.annotation.DaoQuery;
import com.flying.common.annotation.DaoRemove;
import com.flying.common.annotation.DaoUpdate;
import com.flying.common.util.Codes;
import com.flying.framework.annotation.MethodInfo;
import com.flying.framework.annotation.Param;
import com.flying.framework.annotation.Service;
import com.flying.framework.service.AbstractService;
import com.flying.framework.model.ActionResult;
import com.flying.framework.model.ModelFactory;
import com.flying.framework.model.QueryResult;
import com.flying.pas.config.model.Category;
import com.flying.pas.config.model.Config;

@Service(value="ConfigService", desc="配置项")
public class ConfigService extends AbstractService{
	private CategoryService cs;
	
	public void setCategoryService(CategoryService s) {
		this.cs = s;
	}
        
	@MethodInfo("新增")
	@DaoCreate(entity=Config.ENTITY_NAME)
	public Config create(
			@Param(value=Config.CATEGORY_ID, required=true,	desc="CATEGORY ID") Long category_id,
			@Param(value=Config.CATEGORY_CODE, required=false,	desc="CATEGORY CODE") String category_code,
			@Param(value=Config.CONFIG_KEY, required=false,	desc="CONFIG KEY") String config_key,
			@Param(value=Config.CONFIG_VALUE, required=false,	desc="CONFIG VALUE") String config_value,
			@Param(value=Config.DATA_TYPE, required=false,	desc="DATA TYPE") String data_type,
			@Param(value=Config.REMARKS, required=false,	desc="REMARKS") String remarks,
			@Param(value=Config.CREATE_TIME, required=false,	desc="CREATE TIME") Date create_time
		) throws Exception {
		Category c = this.cs.findById(category_id);
		return ModelFactory.create(Config.class, 
				Config.CATEGORY_CODE, c.getCode(),
				Config.CREATE_TIME, new Date());
	}

	@MethodInfo("修改")
	@DaoUpdate(entity=Config.ENTITY_NAME)
	public ActionResult update(
			@Param(value=Config.CONFIG_ID, required=true,	desc="CONFIG ID") Long config_id,
			@Param(value=Config.CONFIG_KEY, required=false,	desc="CONFIG KEY") String config_key,
			@Param(value=Config.CONFIG_VALUE, required=false,	desc="CONFIG VALUE") String config_value,
			@Param(value=Config.DATA_TYPE, required=false,	desc="DATA TYPE") String data_type,
			@Param(value=Config.REMARKS, required=false,	desc="REMARKS") String remarks,
			@Param(value=Config.UPDATE_TIME, required=false,	desc="UPDATE TIME") Date update_time
		) throws Exception {
		return ModelFactory.create(ActionResult.class, 
				Config.UPDATE_TIME, new Date());
	}

	@MethodInfo("删除")
	@DaoRemove(entity=Config.ENTITY_NAME)
	public ActionResult remove(
			@Param(value=Config.CONFIG_ID, required=true,	desc="CONFIG ID") Long config_id
		) throws Exception {
		
		return null;
	}

	@MethodInfo("删除")
	@DaoRemove(entity=Config.ENTITY_NAME)
	public ActionResult removeByCategoryId(
			@Param(value=Config.CATEGORY_ID, required=true,	desc="CATEGORY ID") Long category_id
		) throws Exception {
		
		return null;
	}

	@MethodInfo("搜索")
	@DaoQuery(entity=Config.ENTITY_NAME, pageable=true, modelClass=Config.class, osql="order by config_key")
	public QueryResult<Config> findAll(
			@Param(value=Config.CATEGORY_ID, required=true,	desc="CATEGORY ID") Long category_id,
			@Param(value=Codes.PAGE_NUM, 	required=false, desc="分页页号，默认0") int page,
			@Param(value=Codes.PAGE_SIZE, 	required=false, desc="分页大小，默认10") int rows) throws Exception {
		return null;
	}

	@MethodInfo("搜索")
	@DaoQuery(entity=Config.ENTITY_NAME, pageable=false, modelClass=Config.class, osql="order by config_key")
	public QueryResult<Config> findByCategoryCode(
			@Param(value=Config.CATEGORY_CODE, required=false,	desc="CATEGORY CODE") String category_code) throws Exception {
		return null;
	}

	@MethodInfo("查询")
	@DaoQuery(entity=Config.ENTITY_NAME, single=true, throwsNotFoundException=true )
	public Config findById(
		
			@Param(value=Config.CONFIG_ID, required=true,	desc="CONFIG ID") Long config_id
		) throws Exception {
		return null;
	}

}